package com.abocode.aichat.app.configuration;


import com.aliyun.oss.ClientConfiguration;
import com.aliyun.oss.OSSClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by guanxf on 2015/12/16.
 */
@Configuration
public class ResourceConfiguration {
    @Value("${resource.server.url}")
    private String endpoint;


    @Value("${resource.server.keyid}")
    private String accessKeyId;

    @Value("${resource.server.keysecret}")
    private String accessKeySecret;

    @Value("${resource.server.maxConnections}")
    private int maxConnections;

    @Value("${resource.server.connectionTimeout}")
    private int connectionTimeout;

    @Value("${resource.server.maxErrorRetry}")
    private int maxErrorRetry;

    @Value("${resource.server.socketTimeout}")
    private int socketTimeout;

    @Bean
    public ClientConfiguration clientConfiguration(){
        ClientConfiguration conf = new ClientConfiguration();
        conf.setMaxConnections(maxConnections);
        conf.setConnectionTimeout(connectionTimeout);
        conf.setMaxErrorRetry(maxErrorRetry);
        conf.setSocketTimeout(socketTimeout);
        return  conf;
    }
    @Bean
    public OSSClient ossClient (){
        OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret,clientConfiguration());
        return   client;
    }
}
